import { getStore } from '@/utils/store'
import { getAreaObj } from '@/utils/util'

const userInfo = getStore('userInfo') || {}
const authAreaArr = [userInfo.authProvince, userInfo.authCity, userInfo.authArea, userInfo.authStreet, userInfo.authCommunity].filter(Boolean)

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label: '工单编号',
			prop: 'orderNumber',
		},
		{
			label: '服务组织名称',
			prop: 'organizationName',
		},
		{
			label: '服务对象',
			prop: 'oldmanName',
		},
		{
			label: '身份证号',
			prop: 'oldmanIdCard',
		},
		{
			label: '联系方式',
			prop: 'phoneNumber',
		},
		{
			label: '服务员',
			prop: 'userName',
		},
		{
			label: '服务项目',
			prop: 'itemAbbr',
		},
		{
			label: '服务开始时间',
			prop: 'startServiceTime',
		},
		{
			label: '服务结束时间',
			prop: 'endServiceTime',
		},
		{
			label: '服务时长',
			prop: 'serviceTimeLength',
		},
		{
			label: '服务开始照片',
			prop: 'beforePhotoIds',
			custome: 'img',
		},
		{
			label: '服务结束照片',
			prop: 'photoId',
			custome: 'img',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

const detailConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '工单编号',
			prop: 'orderNumber',
			span: 8,
		},
		{
			label: '服务组织名称',
			prop: 'organizationName',
			span: 8,
		},
		{
			label: '服务对象',
			prop: 'oldmanName',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'oldmanIdCard',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'phoneNumber',
			span: 8,
		},
		{
			label: '服务员',
			prop: 'userName',
			span: 8,
		},
		{
			label: '服务项目',
			prop: 'itemAbbr',
			span: 8,
		},
		{
			label: '服务价格',
			prop: 'price',
			span: 8,
		},
		{
			label: '备注',
			prop: 'note',
			span: 8,
		},
		{
			label: '服务开始照片',
			prop: 'beforePhotoIds',
			custome: 'file',
			limit: 4,
			multiple: true,
			span: 24,
		},
		{
			label: '服务结束照片',
			prop: 'photoId',
			custome: 'file',
			limit: 4,
			multiple: true,
			span: 24,
		},
		{
			label: '服务开始时间',
			prop: 'startServiceTime',
			type: 'date',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '服务结束时间',
			prop: 'endServiceTime',
			type: 'date',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '服务时长',
			prop: 'serviceTime',
			type: 'select',
			dicData: [
				{
					label: '20分钟以下',
					value: 1,
				},
				{
					label: '20分钟及以上',
					value: 2,
				},
			],
			span: 8,
		},
	],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '工单编号',
			prop: 'orderNumber',
			span: 8,
		},
		{
			label: '服务组织名称',
			prop: 'organizationName',
			span: 8,
		},
		{
			label: '服务对象',
			prop: 'oldmanName',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'oldmanIdCard',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'phoneNumber',
			span: 8,
		},
		{
			label: '服务员',
			prop: 'userName',
			span: 8,
		},
		{
			label: '服务项目',
			prop: 'itemAbbr',
			span: 8,
		},
		{
			label: '服务开始时间',
			prop: 'startServiceTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '服务结束时间',
			prop: 'endServiceTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '服务时长',
			prop: 'serviceTime',
			type: 'select',
			dicData: [
				{
					label: '20分钟以下',
					value: 1,
				},
				{
					label: '20分钟及以上',
					value: 2,
				},
			],
			span: 8,
		},
		{
			label: '所属街道社区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			administrationPid: authAreaArr[authAreaArr.length - 1],
			span: 6,
		},
	],
}

export const baseConfig: any = {
	pageName: '居家上门工单',
	addLabel: '',
	dictcodes: [],
	rowKey: 'id',
	// tipLabel: 'projectName',
	api: {
		index: 'view_tblReposOrder_page',
		detail: 'view_tblReposOrder_id',
	},
	auth: {
		index: 'view_tblReposOrder_page',
		detail: 'view_tblReposOrder_id',
	},

	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: 'view_tblReposOrder_id',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			if (query.serviceTime == 1) {
				query = {
					...query,
					serviceTimeLengthLe: 1200,
				}
			} else if (query.serviceTime == 2) {
				query = {
					...query,
					serviceTimeLengthGe: 1200,
				}
			}
			const areaIds = [...authAreaArr, ...(query.areas || [])]
			const areasObj: any = getAreaObj(areaIds, '')
			resolve({
				...query,
				...areasObj,
				serviceTime: undefined,
				areas: undefined,
			})
		})
	},
	searchConfig,
	tableConfig,
	detailConfig,
}
